package com.innovate.nms.domain;

import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.ivan.toolkit.common.Configs;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@NoArgsConstructor
public class InspectHistory {
	
	public static Configs.Instance<InspectHistory> instance = 
			new Configs.Instance<InspectHistory>(InspectHistory.class, true);
	
	@XmlAttribute
	@Setter @Getter
	private int max = 60;
	
	@XmlElement
	@Setter @Getter
	private List<Entry> results = Lists.newLinkedList();
	
	public void addResult(Entry result) {
		
		results.add(result);
		
		while(results.size() > max) {
			results.remove(0);
		}
		
		instance.set();
		
	}
	
	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlRootElement
	@NoArgsConstructor
	public static class Entry {
		
		@XmlAttribute
		@Setter @Getter
		private long time;
		
		@XmlAttribute
		@Setter @Getter
		private long cost;
		
		@XmlElement
		@Setter @Getter
		private Map<String, String> value = Maps.newHashMap();
		
	}

}
